package com.ck.company.controller;

import com.ck.company.service.CpProgramLogService;
import com.ck.constant.PageConstant;
import com.ck.model.company.vo.CpProgramLogVO;
import com.github.pagehelper.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 节目操作日志
 *
 * @author linqiang
 * @version v1.0
 * @date 2018-09-12 9:58
 */
@Controller
@RequestMapping("/programLog")
public class CpProgramLogController {
    private static Logger logger = LoggerFactory.getLogger(CpProgramLogController.class);

    @Autowired
    private CpProgramLogService cpProgramLogService;

    /**
     * 跳转到节目操作日志的列表页面
     *
     * @return string
     */
    @RequestMapping(value = "/listByPage")
    public String listByPage(String programVersion, Model model, Integer pageNum, Integer pageSize) {
        try {
            pageNum = (pageNum == null ? PageConstant.DEFAULT_PAGE_NUM : pageNum);
            pageSize = (pageSize == null ? PageConstant.DEFAULT_PAGE_SIZE : pageSize);
            Page<CpProgramLogVO> page = cpProgramLogService.listByPage(programVersion, pageNum, pageSize);
            model.addAttribute("pageNum", pageNum);
            model.addAttribute("pageSize", pageSize);
            model.addAttribute("result", page.getResult());
            model.addAttribute("total", page.getTotal());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("CpProgramLogController listByPage 分页查询失败:" + e.getMessage());
        }
        return "cp/cp_program_log_list";
    }
}
